class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        int i = 0, j = nums.size() - 1;
        while (i <= j) {
            int index = (i + j) / 2;
            int t = nums[index];
            if (t == target)
                return index;
            else if (t > target)
                j = index - 1;
            else
                i = index + 1;
        }
        return i;
    }
};